﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Telerik.Web.UI;

using HandBook.Data;

public partial class RestList : BasePage
{
    private DataTable _RestList = new DataTable();
    private string _KeyWord = string.Empty;
    private int _Province = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        _KeyWord = SessionManager.CurrentSearch.Keyword;
        _Province = SessionManager.CurrentSearch.Province;
        uxLocation.Province = _Province;
        if (SessionManager.CurrentSearch.Keyword != string.Empty)
            uxRestList.Rebind();
        uxRestList.PagerStyle.PagerTextFormat = "";
    }

    protected void uxRestList_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        var restList = from rest in HandBookData.EatDrinkDB.Restaurants
                       where rest.LongDescription.Contains(_KeyWord)
                       select rest;
        if (_Province != 0)
            restList = restList.Where(r => r.Location.ProvinceID == _Province && r.LocationID == SessionManager.CurrentSearch.Location);
        uxRestList.DataSource = restList;
    }

    protected void uxRestList_PreRender(object sender, EventArgs e)
    {
        uxRestList.PagerStyle.AlwaysVisible = uxRestList.MasterTableView.Items.Count > 0;
    }

    public override void RebindData()
    {
        uxRestList.Rebind();
    }
}
